home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / desaware / stgtools / stg_demo / bnryedit.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-24  |  3.8 KB  |  125 lines

  1. VERSION 4.00
  2. Begin VB.Form BinaryEdit 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "View of Stream"
  5.    ClientHeight    =   3180
  6.    ClientLeft      =   1335
  7.    ClientTop       =   5565
  8.    ClientWidth     =   8760
  9.    ClipControls    =   0   'False
  10.    Height          =   3585
  11.    Left            =   1275
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   3180
  14.    ScaleWidth      =   8760
  15.    Top             =   5220
  16.    Width           =   8880
  17.    Begin VB.ListBox BinaryList 
  18.       BeginProperty Font 
  19.          name            =   "Courier"
  20.          charset         =   0
  21.          weight          =   400
  22.          size            =   9.75
  23.          underline       =   0   'False
  24.          italic          =   0   'False
  25.          strikethrough   =   0   'False
  26.       EndProperty
  27.       Height          =   2370
  28.       Left            =   0
  29.       TabIndex        =   1
  30.       Top             =   120
  31.       Width           =   8775
  32.    End
  33.    Begin VB.CommandButton ButtonOK 
  34.       Caption         =   "Close"
  35.       Default         =   -1  'True
  36.       Height          =   375
  37.       Left            =   7320
  38.       TabIndex        =   0
  39.       Top             =   2640
  40.       Width           =   1095
  41.    End
  42. Attribute VB_Name = "BinaryEdit"
  43. Attribute VB_Creatable = False
  44. Attribute VB_Exposed = False
  45. Option Explicit
  46. ' Close Button.  Unloads the dialog box
  47. Private Sub ButtonOK_Click()
  48.     Unload BinaryEdit
  49. End Sub
  50. ' Get the binary data from global variables and put
  51. ' it into a read-only text box in hexadecimal format
  52. ' with text on the right side.  This is hard coded
  53. ' for a particular sized text box and the ASCII
  54. ' character set.
  55. Private Sub Form_Load()
  56.     Dim num As String
  57.     Dim lines As String
  58.     Dim TextPart As String
  59.     Dim char As String
  60.     Dim i, j As Integer
  61.     Dim NumLines As Integer
  62.     BaseForm.MousePointer = 11
  63.     NumLines = (GlobalSize / 16)
  64.     For i = 0 To NumLines
  65.         ' first the line #
  66.         num = CStr(i)
  67.         Select Case Len(num)
  68.         Case 0:
  69.             num = "000"
  70.         Case 1:
  71.             num = "00" & num
  72.         Case 2:
  73.             num = "0" & num
  74.         Case Else:
  75.         End Select
  76.         lines = lines & num & "  "
  77.         
  78.         ' then the bin data and the chars
  79.         TextPart = ""
  80.         For j = 1 To 16
  81.             If (((i * 16) + j) > GlobalSize) Then
  82.                 num = "  "
  83.                 TextPart = TextPart & " "
  84.             Else
  85.                 char = Mid(GlobalText, (i * 16) + j, 1)
  86.                 num = Hex$(Asc(char))
  87.                 If (Len(num) = 0) Then num = "00" Else
  88.                 If (Len(num) = 1) Then num = "0" & num
  89.                 
  90.                 If (char < " ") Then
  91.                     TextPart = TextPart & "."
  92.                 Else
  93.                     TextPart = TextPart & char
  94.                 End If
  95.             End If
  96.             lines = lines & num & " "
  97.         Next j
  98.         lines = lines & " " & TextPart
  99. On Error GoTo listOverflow
  100.     BinaryList.AddItem lines
  101. On Error GoTo 0
  102.     lines = ""
  103.     Next i
  104.     BaseForm.MousePointer = 0
  105.     Exit Sub
  106. listOverflow:
  107.     MsgBox "The stream is too large." & Chr$(13) & "As much of the stream will be shown as is possible."
  108.     BaseForm.MousePointer = 0
  109.     Exit Sub
  110. End Sub
  111. ' This only allows keypresses that correspond to
  112. ' hexidecimal numbers or text editing to work.
  113. Private Sub ValueBinary_KeyPress(KeyAscii As Integer)
  114.     Dim char As String * 1
  115.     char = LCase$(Chr$(KeyAscii))
  116.     ' Let deletes and backspaces through
  117.     If (KeyAscii = 8) Then Exit Sub
  118.     ' only accept hexadecimal numbers
  119.     If ((char <= "f") And (char >= "a")) Or ((char <= "9") And (char >= "0")) Then
  120.         KeyAscii = Asc(LCase$(Chr$(KeyAscii)))
  121.     Else
  122.         KeyAscii = 0
  123.     End If
  124. End Sub
  125.